﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ModelLibrary;

namespace WebC
{
    public partial class system_roleedit : clsBaseForm
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Ajax.Utility.RegisterTypeForAjax(typeof(system_roleedit));
            if (!IsPostBack)
            {
                loadInfo();
            }
        }

        public void loadInfo()
        {
            clsSys clss = null;
            string sModelName = "";
            try
            {
                clss = new clsSys();
                if (m_Id == 0)
                {
                    if (!checkModelRightById(22, ref sModelName, (clsBaseLib)clss))
                    {
                        errorUrl(string.Format("你没有“{0}”的权限,请与管理员联系！", sModelName));
                        return;
                    }
                }
                else
                {
                    if (Convert.ToInt32(Request["noedit"]) == 1)
                    {
                        if (!checkModelRightById(21, ref sModelName, (clsBaseLib)clss))
                        {
                            errorUrl(sModelName);
                            return;
                        }
                    }
                    else
                    {
                        if (!checkModelRightById(24, ref sModelName, (clsBaseLib)clss))
                        {
                            errorUrl(sModelName);
                            return;
                        }
                    }
                    DataTable dt = clss.getRoleInfoById(m_Id);
                    txtRoleName.Text = Convert.ToString(dt.Rows[0]["rolename"]);
                    txtRoleDesc.Text = Convert.ToString(dt.Rows[0]["roledesc"]);
                }
                sModelFullName = sModelName;

            }
            catch (Exception e)
            {
                errorUrl(Convert.ToString(e));
            }
            finally
            {
                if (clss != null)
                {
                    clss.Dispose();
                }
            }
        }

        int m_Id
        {
            get
            {
                return Convert.ToInt32(Request["id"]);
            }
        }
        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("rolelist.aspx");
        }

        [Ajax.AjaxMethod]
        public bool saveData(int iRId, string sName, string sDesc)
        {
            clsSys clss = null;
            bool bResult = false;
            try
            {
                clss = new clsSys();
                sName = sName.Replace("'", "''");
                sDesc = sDesc.Replace("'", "''");
                bResult = clss.setRoleInfo(iRId, sName, sDesc);
            }
            catch
            {
                bResult = false;
            }
            finally
            {
                if (clss != null)
                {
                    clss.Dispose();
                }
            }
            return bResult;
        }
    }
}
